package com.bi.autotest.operations.payprocessoperation;

import com.auto.base.OperateAppium;
import com.bi.autotest.pages.payprocesspage.MarketPage;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
/**
 *  营销操作
 */
public class MarketOperation extends OperateAppium {

    private MarketPage marketPage;

    public MarketOperation(AndroidDriver androidDriver) {
        super(androidDriver);
        marketPage = new MarketPage(androidDriver);
    }

    //进入账目查询页面
    public boolean LoginAccount() {
        //进入账目查询页面
        exePre();
        boolean isLoginPage = marketPage.isLoginPage();
        return isLoginPage;
    }


    /**
     * 发放立减金XX元
     */
    public boolean giveOutGold(String money) {
        boolean b = LoginAccount();
        print("进入账目查询页面：" + b);
        AndroidElement user_1 = marketPage.getUser_1();
        user_1.click();
        sleep(2000);
        AndroidElement marketing = marketPage.getMarketing();
        marketing.click();
        sleep(2000);
        AndroidElement cis = marketPage.getCIS();
        cis.click();
        sleep(2000);
        input(marketPage.getCISInput(), money);
        AndroidElement giveOutButton = marketPage.getCISGiveOutButton();
        giveOutButton.click();
        sleep(2000);
        AndroidElement confirmButton = marketPage.getCISConfirmButton();
        confirmButton.click();
        sleep(2000);
        AndroidElement agreementConfirm = marketPage.getAgreementConfirm();
        agreementConfirm.click();
        sleep(3000);
        boolean isGiveOutSuccess = marketPage.isGiveOutSuccess("发放成功");
        return isGiveOutSuccess;
    }

    /**
     * 发放折扣优惠，XXX折，次数XX次，期限不输入（无限）
     */
    public boolean giveOutDiscount(String discount,String count) {
        boolean b = LoginAccount();
        print("进入账目查询页面：" + b);
        AndroidElement user_1 = marketPage.getUser_1();
        user_1.click();
        sleep(2000);
        AndroidElement marketing = marketPage.getMarketing();
        marketing.click();
        sleep(2000);
        AndroidElement cis = marketPage.getDiscount();
        cis.click();
        sleep(2000);
        //打几折
        input(marketPage.getDiscountInput(), discount);
        sleep(2000);
        //使用次数
        input(marketPage.getTimesInput(), count);
        sleep(2000);
        AndroidElement giveOutButton = marketPage.getDiscountGiveOutButton();
        giveOutButton.click();
        sleep(2000);
        AndroidElement confirmButton = marketPage.getDiscountConfirmButton();
        confirmButton.click();
        sleep(2000);
        AndroidElement agreementConfirm = marketPage.getAgreementConfirm();
        agreementConfirm.click();
        sleep(3000);
        boolean isGiveOutSuccess = marketPage.isGiveOutSuccess("设置成功");
        switchAppContext();
        sleep(2000);
        pressCloseButton();
        sleep(2000);
        pressBackKey();
        sleep(2000);
        return isGiveOutSuccess;
    }

    public void exePre() {
        driver.findElementByXPath("//android.widget.TextView[@text='https://msdev.188yd.com/wxh/seller/receiptsOrder']").click();
        sleep(2000);
        driver.findElementByXPath("//android.widget.TextView[@text='https://msdev.188yd.com/wxh/seller/receiptsOrder']").click();
        sleep(5000);
        System.out.println("打开收藏h5");
        switchH5_C_W(marketPage.TO_LOGIN_SUCCESSPAGE);
    }
}
